$(function () {
    /**
     * 打开app
     */
    $('.ect-open-app').click(function () {
        location.href = '/wechat/openApp';
    });
});

/**
 * 页面重定向
 * @param url
 * @param data
 */
function redirect(url, data = null, e = null) {
    if (e) {
        e.stopPropagation();
    }
    if (data) {
        $.each(data, function (i, item) {
            url += '/' + item;
        });
        console.log(url);
    }
    location.href = url;
}

/**
 * 切换导航
 * @param obj
 */
function switchNav(obj) {
    obj.addClass('active').siblings().removeClass('active');
}

/**
 * 打开隐藏模块
 * @param obj
 * @param hideObj
 */
function openHideDiv(obj, hideObj = []) {
    $('body,html').addClass('ect-overflow-hidden');
    $.each(obj, function (i, item) {
        $(item).show();
    });

    if (hideObj.length > 0) {
        $.each(hideObj, function (i, item) {
            $(item).hide();
        });
    }
}

/**
 * 隐藏打开的模块
 * @param obj
 * @param openObj
 */
function closeOpenDiv(obj, openObj = []) {
    $('body,html').removeClass('ect-overflow-hidden');
    $.each(obj, function (i, item) {
        $(item).hide();
    });

    if (openObj.length > 0) {
        $.each(openObj, function (i, item) {
            $(item).show();
        });
    }
}

/**
 * 复制输入框内容
 * @param obj
 * @param msg
 */
function copyInputValue(obj, msg = '复制成功') {
    var input = document.getElementById(obj);
    input.setAttribute('readonly', 'readonly');
    input.setSelectionRange(0, input.value.length);
    input.select();
    try {
        document.execCommand('copy', true);
        layer.msg(msg);
    } catch (err) {
        layer.msg('复制失败');
    }
}